/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



package fmon.util;

//~--- JDK imports ------------------------------------------------------------

import java.io.File;
import java.io.FilenameFilter;

import java.util.Observable;

/**
 *
 * @author jio
 */
public class Crawler extends Observable {
    public Crawler() {}

    private boolean isSymbolicLink(File file) {
        boolean result = false;

        try {
            if (!file.getCanonicalFile().equals(file.getAbsoluteFile())) {
                System.out.println("Symbolic link found, skipping...");

                result = true;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    public void crawl(File root) {
        File[] files = root.listFiles();

        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    if (!isSymbolicLink(file)) {
                        crawl(file);
                    }
                } else {
                    
                    if (file.canExecute()) {
                        HelperClass.retrieveChecksum(file.getAbsolutePath());
                        this.setChanged();
                        this.notifyObservers(file);
                    }
                }
            }
        }
    }
}


//~ Formatted by Jindent --- http://www.jindent.com
